package ssq.gamest.wolfmankill.port_android;

import ssq.utils.port_android.UtilsApp;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class App extends UtilsApp {
  protected static final String WEBSOCKET_PORT = "websocket_port";
  protected static final int DEFAULT_WEBSOCKET_PORT = 44343;

  private static App instance;

  public static App getApp() {
    return instance;
  }

  /**
   * Init app context which is essential when using Utils. Must be called before
   * Custom App's onCreate.
   */
  @Override
  public void onCreate() {
    super.onCreate();
    instance = this;
  }

  protected static int getWsServerPort() {
    SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(getApp());
    int serverPort = Integer.parseInt(pref.getString(App.WEBSOCKET_PORT, String.valueOf(App.DEFAULT_WEBSOCKET_PORT)));
    return serverPort;
  }
}
